<?php

namespace App\Http\Controllers\H5;

use App\WeChat\WechatOauthUser;
use EasyWeChat\Factory;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    protected $officialAccount;
    protected $payment;
    protected $oauthUser;
    protected $sysMessageView = 'h5.message';

    public function __construct(Request $request)
    {
        parent::__construct($request);

        $this->middleware(function (Request $req, $next){
            $this->officialAccount = Factory::officialAccount(config('wechat.official_account.default'));
            $this->payment = Factory::payment(config('wechat.payment.default'));
            $this->oauthUser = new WechatOauthUser(session('wechat.oauth_user', []));

            $this->assign([
                'jssdk_config'=>$this->officialAccount->jssdk->buildConfig(
                    [
                        'onMenuShareQQ',
                        'onMenuShareWeibo',
                        'scanQRCode',
                        'chooseImage',
                        'uploadImage',
                        'getLocation',
                        'openLocation'
                    ],
                    false, false, false)
            ]);
            return $next($req);
        });
    }
}
